1. Introduction

This plugin makes it easy to both send and receive Twitter messages inside a Grails application.

Installation

grails install-plugin twitter4j

Configuration

Enable your application in twitter.

Log into your twitter account (eg. http://www.twitter.com/yourname) and then go to https://dev.twitter.com/apps/new to register your app.

Select your application type as "Client"

Make a note of your Consumer Key and Consumer Secret, you will need it shortly

Getting your requestToken from Twitter

run your app, and goto http://localhost:8080/yourApp/twitter4j- enter the Consumer Key and Secret and click "Request token"

Click the link on the next screen, and follow the instructions to obtain your PIN. Enter the pin-code and click "Verify pin"

Paste the configuration code into your Config.groovy file and restart the app

Test if it works

Goto http://localhost:8080/yourApp/twitter4j/status and enter a twitter-message. If it works, you should be able to see your update on your twitter page: http://www.twitter.com/yourname

Examples

The following are some simple examples to give you a feel for the plugin.

Sending a twitter update

In a controller or service

class SomeController {

def twitter4jService

def someAction = { twitter4jService.updateStatus("This is a status-update from twitter") } }

Getting your own latest updates

class SomeController {

def twitter4jService

def someAction = { def updates = twitter4jService.getUserTimeline() // of type ResponseList<Status> [statusUpdates: updates] } }

More than one twitter-account? (untested)

Alter your configuration to:

twitter {
    disableTwitter4jController = true
    'default' {
        OAuthConsumerKey = '******'
        OAuthConsumerSecret = '************'
        OAuthAccessToken = '************'
        OAuthAccessTokenSecret = '************'
    }
    'otherAccount' {
        OAuthConsumerKey = '******'
        OAuthConsumerSecret = '************'
        OAuthAccessToken = '************'
        OAuthAccessTokenSecret = '************'
    }
}

And before your twitter-calls do this

twitter4j.connect('otherAccount')

Where to get more information.

The plugin exposes the Twitterj4 API through @Delegation.

Find the Twitter4j homepage here: